import sys, pygame, random
from pygame.locals import *

pygame.init()

size = width, height = 480, 480
screen = pygame.display.set_mode(size)
clock = pygame.time.Clock()

black, red, blue, white = (0, 0, 0), (255, 0, 0), (0, 0, 255), (255, 255, 255)
lose, tie, win = xxx, empty, ooo = -1, 0, 1
human = ooo

def draw_game():
    pygame.draw.rect(screen, white, (0, 0, width, height))

    pygame.draw.line(screen, black, (160, 0), (160, 480), 5)
    pygame.draw.line(screen, black, (320, 0), (320, 480), 5)
    pygame.draw.line(screen, black, (0, 160), (480, 160), 5)
    pygame.draw.line(screen, black, (0, 320), (480, 320), 5)

    for row, line in enumerate(board):
        for col, val in enumerate(line):
            if val == xxx:
                    # Draw an X as two crossing lines.

                upper_left = (col * 160 + 5, row * 160 + 5)
                lower_right = (col * 160 + 155, row * 160 + 155)
                pygame.draw.line(screen, red, upper_left, lower_right, 5)

                upper_right = (col * 160 + 155, row * 160 + 5)
                lower_left = (col * 160 + 5, row * 160 + 155)
                pygame.draw.line(screen, red, upper_right, lower_left, 5)
            elif val == ooo:
                rect = (col * 160 + 5, row * 160 + 5, 150, 150)
                pygame.draw.ellipse(screen, blue, rect, 5)
            else:
                assert val == empty
                continue

    pygame.display.flip()
def restart():
    global board, turn, human
    human *= -1
    board = [[empty] * 3, [empty] * 3, [empty] * 3]
    turn = xxx
    draw_game()
    pygame.display.flip()

restart()

